<<<<<<< Updated upstream ======= >>>>>>> Stashed changes <<<<<<< Updated upstream Quarto Introduction – BIOS 6312 - Spring 2025 ======= BIOS 6312 - Spring 2024 - Quarto Introduction >>>>>>> Stashed changes <<<<<<< Updated upstream ======= >>>>>>> Stashed changes <<<<<<< Updated upstream ======= >>>>>>> Stashed changes
<<<<<<< Updated upstream

Quarto Introduction

Author

Your Name

>>>>>>> Stashed changes

Learning Objectives

  1. Open the quarto introduction file in your Rstudio and render to create an html output file
  2. Learn some basic markdown syntax to include text and run code
  3. <<<<<<< Updated upstream
  4. Alter the YAML to include your name and output to a different file format (e.g. docx)
  5. =======
  6. Alter the YAML to include your name and output to a different file format (e.g. docx)
  7. >>>>>>> Stashed changes

R packages used

For this introduction, I used three R packages. If you have never used these before, they will need to be installed once, e.g.

<<<<<<< Updated upstream
install.packages("ggplot2")
install.packages("rms")
install.packages("Hmisc")
=======
install.packages("ggplot2")
install.packages("rms")
install.packages("Hmisc")
>>>>>>> Stashed changes

If they have already been installed, you can load these packages.

library(ggplot2)
library(rms)
<<<<<<< Updated upstream =======
Warning: package 'rms' was built under R version 4.3.2
>>>>>>> Stashed changes
Loading required package: Hmisc

<<<<<<< Updated upstream
Attaching package: 'Hmisc'
The following objects are masked from 'package:base':

    format.pval, units
library(Hmisc)
======= Attaching package: 'Hmisc'
The following objects are masked from 'package:base':

    format.pval, units
library(Hmisc)
>>>>>>> Stashed changes

Quarto

Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see https://quarto.org.

Quarto includes many more features than I will cover in this course. It is not a learning objective of this course that you learn all of the features included in Quarto. Instead, I want to cover a few of the most useful things and provide a starting point for those interested in learning more.

<<<<<<< Updated upstream

Running Code

When you click the Render button a document will be generated that includes both content and the output of embedded code. You can embed code like this:

1 + 1
=======

Running Code

When you click the Render button a document will be generated that includes both content and the output of embedded code. You can embed code like this:

1 + 1
>>>>>>> Stashed changes
[1] 2

You can add options to executable code like this

[1] 4

The echo: false option disables the printing of code (only output is displayed).

<<<<<<< Updated upstream

Plots

You can include plots

ggplot(cars, aes(x=speed, y=dist)) + 
  geom_smooth() + 
  xlab("Speed (mph)") + 
  ylab("Stopping Distance (feet)")
`geom_smooth()` using method = 'loess' and formula = 'y ~ x'

Date recorded in the 1920s
=======

Plots

You can include plots

ggplot(cars, aes(x=speed, y=dist)) + 
  geom_smooth() + 
  xlab("Speed (mph)") + 
  ylab("Stopping Distance (feet)")
`geom_smooth()` using method = 'loess' and formula = 'y ~ x'

Date recorded in the 1920s
>>>>>>> Stashed changes

Speed and stopping distance of cars

Tables

And tables that are simple text

<<<<<<< Updated upstream
# Create some data
set.seed(12345) # Fpr reproducibility
exampledata <- data.frame(age=rnorm(500,50,5),
                          sbp=rnorm(500,120,12),
                          trt=factor(sample(c("Drug","Placebo"), 500, replace=TRUE))
)
f <- summaryM(age + sbp ~ trt, data=exampledata, test=TRUE)
print(f, digits=2)
=======
# Create some data
set.seed(12345) # Fpr reproducibility
exampledata <- data.frame(age=rnorm(500,50,5),
                          sbp=rnorm(500,120,12),
                          trt=factor(sample(c("Drug","Placebo"), 500, replace=TRUE))
)
f <- summaryM(age + sbp ~ trt, data=exampledata, test=TRUE)
print(f, digits=2)
>>>>>>> Stashed changes


Descriptive Statistics  (N=500)

+---+------------------+------------------+------------------------+
|   |Drug              |Placebo           |  Test                  |
|   |(N=260)           |(N=240)           |Statistic               |
+---+------------------+------------------+------------------------+
|age|        47/50/53  |        47/51/54  | F=0.5 d.f.=1,498 P=0.48|
+---+------------------+------------------+------------------------+
|sbp|       113/120/129|       112/120/128|F=0.02 d.f.=1,498 P=0.89|
+---+------------------+------------------+------------------------+

Table can also be formatted to improve appearance. Here is an html version of the same table.

<<<<<<< Updated upstream
html(f, digits=3)
=======
html(f, digits=3)
>>>>>>> Stashed changes
Descriptive Statistics (N=500).
Drug
N=260
Placebo
N=240
Test Statistic
age 47.4 50.3 53.2 47.0 50.7 54.0 F1 498=0.5, P=0.479
sbp 113 120 129 112 120 128 F1 498=0.02, P=0.89
a b c represent the lower quartile a, the median b, and the upper quartile c for continuous variables.
Test used: Wilcoxon test .

Quarto YAML

The beginning of this document of the document contains metadata that controls the document appearance, output format, and many other options. The current lines were automatically generated when I create a new document (File > New File > Quarto Document…)

For longer documents, it can be useful to add a table of contents. A simple toc can added with the line.

<<<<<<< Updated upstream
toc: true
=======
toc: true
>>>>>>> Stashed changes

Also, the default output type is an html document. This is a good choice, but if you prefer other options, you can alter the yaml to produce Word files, PDFs, or many other options. Tab-completion is supported to see the various options.

In order to create PDFs you will need to install a recent distribution of TeX. We recommend the use of TinyTeX (which is based on TexLive), which you can install with the following command:

quarto install tinytex

More details on authoring Quarto documents in Rstudio are available elsewhere.

Thing to try

  1. Alter the YAML to include your name
  2. <<<<<<< Updated upstream
  3. Alter the YAML to output to a different file format, e.g. docx
  4. =======
  5. Alter the YAML to output to a different file format, e.g. docx
  6. >>>>>>> Stashed changes
  7. Add some text, code, or graphics and render the document

<<<<<<< Updated upstream ======= >>>>>>> Stashed changes